package com.cy.account.tx;

import com.cy.account.entity.AccountMessage;
import com.cy.account.service.AccountService;
import com.cy.account.util.JsonUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(topic = "orderTopic",consumerGroup = "accountGroup")
@Component
public class AccountConsumer implements RocketMQListener<String> {

    @Autowired
    private AccountService accountService;

    @Override
    public void onMessage(String json) {
        // json --> AccountMessage
        AccountMessage amsg = JsonUtil.from(json, AccountMessage.class);
        // 调用业务方法
        accountService.decrease(amsg.getUserId(),amsg.getMoney());

    }
}
